package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.SignStore;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISignStoreService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("signStore")
public class SignStoreController {
    @Autowired
    private ISignStoreService signStoreService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        model.addAttribute("pageInfo", signStoreService.query(qo));
        return "signStore/list";
    }

    @RequestMapping("saveOrUpdate")
    public String saveOrUpdate(MultipartFile file, SignStore entity) {
        if (file != null && file.getSize() > 0) {
            String upload = UploadUtil.uploadQiniu(file);
            entity.setProductUrl(UploadUtil.QINIU_PATH + "/" + upload);
        }
        signStoreService.saveOrUpdate(entity);
        return "redirect:/signStore/list.do";
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id) {
        signStoreService.delete(id);
        return new JSONResult();
    }


   /*@RequestMapping("getContentById")
    @ResponseBody
    public SignStoreContent getContentById(Long id) {
        return signStoreService.getContentById(id);
    }
*/

}
